package com.kaishengit.service;

import java.util.List;

import com.kaishengit.dao.MemberDao;
import com.kaishengit.dao.MessageDao;
import com.kaishengit.entity.Member;
import com.kaishengit.entity.Message;
import com.kaishengit.util.GetTime;
import com.kaishengit.util.Pager;

public class MessageService {

	MessageDao dao = new MessageDao();
	public Pager findAll(String pid,int num) {
		Pager pager = dao.findAll(pid,num);
		List<Message> list = pager.getResult();
		for(Message m:list){
			String mid = m.getMid();
			MemberDao mdao = new MemberDao();
			Member member = mdao.findById(mid);
			m.setMemberName(member.getM_name());
		}
		return pager;
	}

	public void insert(String content, String mid, String pid,String time) {
		Message mes = new Message();
		mes.setMid(mid);
		mes.setMes_content(content);
		mes.setMes_id(GetTime.getTime());
		mes.setMes_createTime(time);
		mes.setPid(pid);
	
		dao.insert(mes);
	}
	
	

}
